package com.th.supcom.pds.drugsupply.client.mvc;

import net.carefx.fc.component.editor.client.EMREditorPanel;
import net.carefx.fc.component.editor.client.utils.ActivexUtils;
import net.carefx.framework.container.client.context.AppContext;
import net.carefx.framework.container.client.page.PageContext;

import com.extjs.gxt.ui.client.Style.HideMode;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.View;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.th.supcom.pds.common.enums.ComponentType;
import com.th.supcom.pds.common.utils.ClientUtils;
import com.th.supcom.pds.drugsupply.client.common.PdsPropertyMaitainModuleEvents;
import com.th.supcom.pds.drugsupply.client.widget.PdsMaintainMainPanel;

/**
 * PhamBasicInfo视图.
 * 
 * 药品信息.
 */
public class PdsPropertyMaintainView extends View
{
    /** 公司版权信息. */
    public static final String copyright = "Copyright 2014, TH Supcom Corporation";

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";

    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";

    private PdsMaintainMainPanel m_pdsMaintainMainPanel;

    /**
     * @param controller
     */
    public PdsPropertyMaintainView (final Controller controller)
    {
        super (controller);
    }

    @Override
    protected void handleEvent (final AppEvent event)
    {
        if (PdsPropertyMaitainModuleEvents.UI_INIT.equals (event.getType ()))
        {
            final PageContext context = event.getData ();
            this.initUI (context);
        }
        else if (PdsPropertyMaitainModuleEvents.QUERY_INFO.equals (event.getType ()))
        {
            onQueryInfo ();
        }
        else if (PdsPropertyMaitainModuleEvents.ADD_DRUG_INFO.equals (event.getType ()))
        {
            onAddInfo ();
        }
        else if (PdsPropertyMaitainModuleEvents.EDIT_INFO.equals (event.getType ()))
        {
            onModifyInfo ();
        }
        else if (PdsPropertyMaitainModuleEvents.REFRESH_DRUG_INFO.equals (event.getType ()))
        {
            onRefreshInfo ();
        }

    }

    /**
     * 初始化容器面板.
     * 
     * @param context
     */
    private void initUI (final PageContext context)
    {
        final LayoutContainer mainLayoutContainer = context.getContainer ();
        mainLayoutContainer.setLayout (new FitLayout ());
        mainLayoutContainer.setHideMode (HideMode.OFFSETS);
        m_pdsMaintainMainPanel = new PdsMaintainMainPanel ();
        EMREditorPanel emrEditorPanel = new EMREditorPanel ("pds_nopaid_ip" + (ActivexUtils.getEMREditorIndex ()), ComponentType.TJTool);

        mainLayoutContainer.add (m_pdsMaintainMainPanel);
        mainLayoutContainer.add (emrEditorPanel);
    }

    private void onAddInfo ()
    {
        m_pdsMaintainMainPanel.addInfo ();
    }

    private void onModifyInfo ()
    {
        String deptCode = ClientUtils.getOrgModel().getOrgCode();
        m_pdsMaintainMainPanel.modifyInfo (deptCode);
    }

    private void onQueryInfo ()
    {
        m_pdsMaintainMainPanel.queryInfo ();
    }

    private void onRefreshInfo ()
    {

        m_pdsMaintainMainPanel.refreshInfo ();
    }

}